<script type="text/javascript">
$(function($){
	var selectBox = {};
	var selectLast = null;
	var separate = '-';
	$('.selectBox a').live('click',function(){
		var $this = $(this);
		var parents_ul = $this.parents('ul');
		var parents_ids = parents_ul[0].id.split(separate);
		var child_id = parents_ids[0]+separate+(+parents_ids[1]+1);
		var id = $this.attr('data');
		selectLast = parents_ids[1];
		selectBox[selectLast] = id+separate+$this.html();

		var pids='',pids_separate = ',';
		var pnames='',pnames_separate = ' >> ';
		var temp='';
		for(var i=1,j=selectLast;i<=j;i++){
			temp = selectBox[i].split(separate);
			if(i==j)
				pids_separate = pnames_separate = '';
			pids += temp[0] + pids_separate;
			pnames += temp[1] + pnames_separate;
		}
		$('#pnames').html(pnames);
		$('#pids').html(pids);
		
		parents_ul.find('li.cur').removeClass('cur');
		$this.parent('li').addClass('cur');
		$.get(root+"/goods/classes/choice/"+id, function(data){
			var sub = '<div class="separate">▶</div>';
			var hasData = false;
			for(var key in data.list){
				var item = data.list[key];
				if(!hasData){
					hasData = true;
					sub += '<ul class="selectBox" id="'+child_id+'">';
				}
				sub += '<li><a data="'+item['id']+'">'+item['name']+'</a></li>';
			}
			parents_ul.nextAll().remove();
			if(hasData){
				sub += '</ul>';
				parents_ul.after(sub);
			}
		},'json');
	});

	var fname = 'goodsclass_parentname';
	var fid = 'goodsclass_parentid';
	<?php if(isset($from) && $from == 'brand'){?>
		fname = 'classname';
		fid = 'brand_classid';
	<?php }?>
	$('.choice').click(function(){
		$('#'+fname).html($('#pnames').html());
		$('#'+fid).val(selectBox[selectLast].split(separate)[0]);
		$.colorbox.close();
	});
})
</script>
<div class="winBox-outer">
	<div class="list-tab">
		<ul>
			<li class="cur">选择上级分类</li>
		</ul>
	</div>
	<div>
		<?php 
		if(isset($list) && count($list)){
			echo '<ul class="selectBox" id="node-1">';
			foreach ($list as $item) {
				echo '<li><a data=',$item['id'],'>',$item['name'],'</a></li>';
			}
			echo '</ul>';
		}else{
			echo '-无-';
		}?>
	</div>
	<div class="selectResult">所选择上级分类：
		<span id="pnames"><?php echo $parentname;?></span>
		<input type="hidden" value="" id="pids"/>
		<input type="button" value="确定" class="choice"/>
	</div>
</div>